package cn.gson.querydsl.plugin;

import com.blazebit.persistence.CriteriaBuilderFactory;
import com.blazebit.persistence.querydsl.BlazeJPAQuery;
import com.querydsl.core.types.EntityPath;
import jakarta.persistence.EntityManagerFactory;
import lombok.AllArgsConstructor;

/**
 * <p>****************************************************************************</p>
 * <ul style="margin:15px;">
 * <li>Description : querydsl-solon-plugin</li>
 * <li>Version     : 1.0</li>
 * <li>Creation    : 2024年07月20日</li>
 * <li>@author     : ____′↘夏悸</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
@AllArgsConstructor
public class BlazeJPAQueryFactory {
    private final EntityManagerFactory emf;

    private final CriteriaBuilderFactory cbf;

    public <T> BlazeJPAQuery<T> selectFrom(EntityPath<T> from) {
        BlazeJPAQuery<T> query = new BlazeJPAQuery<>(emf.createEntityManager(), cbf);
        return query.select(from).from(from);
    }
}
